

var LayuiManager = function () { };
LayuiManager.prototype = {
    getTableOption: function (id, elem, url, cols) {
        return {
            id: id,
            elem: elem,
            url: url,
            method: 'post',
            page: true,
            limits: [2, 10, 20, 30, 60, 90, 150, 300],
            limit: 10,
            request: {pageName: 'pageIndex', limitName: 'pageSize'},
            response: {
                statusName: 'code',   //数据状态的字段名称，默认：code
                statusCode: 0,        //成功的状态码，默认：0
                msgName: 'message',        //状态信息的字段名称，默认：msg
                countName: 'total',     //数据总数的字段名称，默认：count
                dataName: 'data'        //数据列表的字段名称，默认：data
            },
            loading: true,
            even: true,
            size: 'sm',
            cols: cols
        };
    },
    parentCreateTab: function (url, config) {
        this.parentCloseTab(config.id);
        var tabTitleDiv = $('.layui-tab[lay-filter="tab"]', window.parent.document).children('.layui-tab-title');
        var exist = tabTitleDiv.find('li[lay-id=' + config.id + ']');
        if (exist.length > 0) {
            //切换到指定索引的卡片
            parent.layuiElement.tabChange('tab', config.id);
        } else {
            var index = layer.load(1);
            setTimeout(function () {
                layer.close(index);
                var iframeElem = document.createElement('iframe');
                iframeElem.src = url;
                iframeElem.style = 'width:100%;height:100%;border:none;outline:none;';
                console.log(parent.layuiElement);
                parent.layuiElement.tabAdd('tab', { title: config.title, content:iframeElem.outerHTML, id: config.id });
                parent.layuiElement.tabChange('tab', config.id);
            }, 100);
        }
    },
    parentCloseTab: function (id) {
        parent.layuiElement.tabDelete('tab', id);
    }

};
var layuiManager = new LayuiManager();